package game;

/**
 * Game Configuration is for the server to initialize the new game with these settings.
 * @author Sarun Wongtanakarn 5510546166
 * @author Apiwat Jierakulpanit 5510546212
 * @Version 2013.05.01
 */
public class GameConfiguration {
	public final int MAX_PLAYER;
	public final int STARTING_MONEY;
	public final int STARTING_LENGTH;
	public final int STARTING_HEALTH;
	public final int MAXIMUM_HEALTH;
	public final int INTERVAL;
	public final Field FIELD;

	/**
	 * Creates a new game configuration.
	 * 
	 * @param player
	 *            maximum player.
	 * @param money
	 *            starting money for each player.
	 * @param length
	 *            starting length for each snake.
	 * @param health
	 *            starting health for each snake.
	 * @param maxHealth
	 *            maximum health for each snake.
	 * @param width
	 *            width of the field.
	 * @param height
	 *            height of the field.
	 * @param interval
	 *            game speed (millisecond per frame).
	 */
	public GameConfiguration(int player, int money, int length, int health,
			int maxHealth, int width, int height, int interval) {
		
		if (player > 8 || player < 1) 
			throw new IllegalArgumentException();
		
		MAX_PLAYER = player;
		STARTING_MONEY = money;
		STARTING_LENGTH = length;
		STARTING_HEALTH = health;
		MAXIMUM_HEALTH = maxHealth;
		FIELD = new Field(width, height);
		INTERVAL = adjustInterval(interval, 25);
	}

	/** 
	 * Returns the adjust interval value.
	 * @return the value that has been adjusted
	 */
	private int adjustInterval(int value, int factor) {
		final int MIDDLE_VALUE = 175;
		final int SPEED_SCALE_FACTOR = factor;
		if (value > MIDDLE_VALUE) {
			value = MIDDLE_VALUE - (value - MIDDLE_VALUE)
					- SPEED_SCALE_FACTOR;
		} else if (value < MIDDLE_VALUE) {
			value = MIDDLE_VALUE + (MIDDLE_VALUE - value);
		}
		return value;
	}

}
